/**
 * 单例
 * 不管类实例化多少次，得到的结果都是同一个实例
 */

/*class Afei {
    constructor(name,age,sex){
        this.name = name
        this.age = age
        this.sex = sex
    }

    showName(){
        alert(this.name)
    }

    showAge(){
        alert(this.age)
    }

    showSex(){
        alert(this.sex)
    }
}

let a = new Afei("阿飞",18,"男")
let b = new Afei("阿飞",18,"男")

console.log(a === b);*/


/*class F {
    constructor(){
        // return 1
        return {x:50}
    }
    a(){}
    b(){}
}*/

/*function F(){
    // return 1;
    return {x:1}
}*/

let F = (function () {
        let ins = null

    return class  {
        constructor(){
            /*if(ins){
                return ins
            }else {
                ins = this

            }*/

            if (ins) return ins
            ins = this;
            console.log(this);
            //code

        }
    }
})();

let a = new F()
let b = new F()
console.log(a ===b);